package com.yunhe.device.controller.base;

import com.yunhe.common.exception.ArgumentErrorException;
import com.yunhe.common.exception.ObjectNotFoundException;
import com.yunhe.common.exception.UniqueConstraintsException;
import com.yunhe.common.model.ResultObject;
import com.yunhe.device.domain.base.PointDataType;
import com.yunhe.device.model.base.AnlogTypeQueryCondition;
import com.yunhe.device.model.base.AnlogTypeVo;
import com.yunhe.device.model.base.StatusVo;
import com.yunhe.device.service.base.AnlogTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName AanlogTypeController
 * @Description TODO
 * @Author HeTao
 * @Date 2021/7/13 17:38
 * @Version 1.0
 **/
@Api(value = "AanlogType", description = "点号类型维护", tags = {"Base_AanlogType"})
@RestController
@RequestMapping("/types/anlogType")
public class AnlogTypeController {

    @Autowired
    private AnlogTypeService anlogTypeService;

    /**
     * 新增点号类型
     * @param anlogType 点号类型对象
     */
    @ApiOperation("新增点号类型")
    @RequestMapping(method = RequestMethod.POST)
    public ResultObject<PointDataType> createAnlogType(@RequestBody PointDataType anlogType)
            throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException {
        PointDataType newAnlogType = anlogTypeService.createAnlogType(anlogType);
        return new ResultObject<>(newAnlogType);
    }

    /**
     * 查询点号类型列表
     * @param anlogTypeQueryCondition 点号类型对象
     */
    @ApiOperation("查询点号类型列表")
    @RequestMapping(value = "/getAnlogTypeByCondition",method = RequestMethod.POST)
    public ResultObject<List<AnlogTypeVo>> getAnlogTypeByCondition(@RequestBody AnlogTypeQueryCondition anlogTypeQueryCondition) {
        Iterable<AnlogTypeVo> results  = anlogTypeService.getAnlogTypeByCondition(anlogTypeQueryCondition);
        return new ResultObject(results);
    }

    /**
     * 查询点号类型列表
     * @param id 点号类型对象
     */
    @ApiOperation("查询点号类型详情")
    @RequestMapping(value = "/getAnlogTypeById",method = RequestMethod.GET)
    public ResultObject<AnlogTypeVo> getAnlogTypeById(@ApiParam(value = "id",required = true) @RequestParam(value = "id") Long id) throws ObjectNotFoundException {
        AnlogTypeVo anlogTypeVo = anlogTypeService.getAnlogTypeById(id);
        return new ResultObject<>(anlogTypeVo);
    }

    /**
     * 根据id删除点号类型
     * @param id 点号类型对象
     */
    @ApiOperation("根据id删除点号类型")
    @RequestMapping(value = "/deleteAnlogTypeById",method = RequestMethod.POST)
    public ResultObject<Void> deleteAnlogTypeById(@ApiParam(value = "id",required = true) @RequestParam(value = "id") Long id) throws ArgumentErrorException, ObjectNotFoundException {
        anlogTypeService.deleteAnlogTypeById(id);
        return new ResultObject<>();
    }

    /**
     * 修改点号类型信息
     * @param anlogType 点号类型对象
     */
    @ApiOperation("修改点号类型信息")
    @PostMapping(value = "/updateAnlogType")
    public ResultObject<PointDataType> updateAnlogType(@RequestBody PointDataType anlogType) throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException {
        PointDataType newAnlogType = anlogTypeService.updateAnlogType(anlogType);
        return new ResultObject<>(newAnlogType);
    }

    /**
     * 点号类型禁用恢复
     * @param statusVo 点号类型对象
     */
    @ApiOperation("点号类型禁用恢复")
    @PostMapping(value = "/updateAnlogTypeStauts")
    public ResultObject<Void> updateAnlogTypeStatus(@RequestBody StatusVo statusVo) throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException {
        anlogTypeService.updateAnlogTypeStatus(statusVo);
        return new ResultObject<>();
    }

    /**
     * 根据设备类型查询点号类型列表
     * @param equipTypeName 点号类型对象
     */
    @ApiOperation("根据设备类型查询点号类型列表")
    @GetMapping (value = "/getAnlogTypeByEquipTypeName")
    public ResultObject<List<PointDataType>> getAnlogTypeByEquipTypeName(@ApiParam(value = "equipTypeName",required = false) @RequestParam(value = "equipTypeName",required = false) String equipTypeName) throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException {
        Iterable<PointDataType> newAnlogTypes = anlogTypeService.getAnlogTypeByEquipTypeName(equipTypeName);
        return new ResultObject(newAnlogTypes);
    }
}
